<template>
  <el-dialog
    title="发送设置"
    :visible.sync="$attrs.visableIf"
    @close="handleCloseDialog"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    append-to-body
    width="1200px"
  >
    <div class="content-big">
      <el-form
        ref="queryParams"
        :model="queryParams"
        size="small"
        :inline="true"
      >
        <el-form-item label="" prop="name">
          <el-input
            placeholder="请输入企微号"
            v-model="queryParams.name"
            @keyup.enter.native="handleQuery"
            class="x-input-select"
            style="width: 240px"
          >
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="" prop="name">
          <el-select
            v-model="queryParams.group"
            size="small"
            style="width: 120px"
            filterable
            placeholder="全部分组"
            @change="handleQuery"
          >
            <el-option
              v-for="item in groupList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-table
        :data="tableDataList"
        ref="multipleTable"
        @selection-change="handleSelectionChange"
        max-height="500"
      >
        <el-table-column type="selection" width="60" align="center" />
        <el-table-column
          :label="item.label"
          v-for="(item, index) in tableColumns"
          :key="index"
          :prop="item.key"
          :min-width="item.minWidth ? item.minWidth : ``"
          :fixed="item.fixed ? item.fixed : false"
          :show-overflow-tooltip="true"
        >
          <!--用于表格自定义-->
          <template slot-scope="scope">
            <div v-if="item.key == 'name'">
              <div class="userInfo">
                <img src="../../../assets/images/profile.jpg" />
                <div class="user-big">
                  <div class="name">群聊</div>
                  <div class="label">成员<span>3</span></div>
                </div>
              </div>
            </div>
            <div v-else>
              {{ scope.row[item.key] }}
            </div>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button type="text" @click="handleSetting(scope.row)"
              >设置</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 10"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <div class="tag_foot flex aligncenter pt-10">
        <div
          class="c_primary commhover"
          v-if="!checked"
          @click="handleSelectAll"
        >
          选择全部
        </div>
        <div class="c_primary commhover" v-else @click="handleSelectClear">
          取消全选
        </div>
        <div class="ml-10">
          已选：<span class="c_primary">{{ multipleSelection.length }}</span>
          个
        </div>
        <el-button
          class="ml-10"
          size="small"
          :disabled="!checked"
          type="primary"
          plain
          @click="handleSetting"
          >批量操作</el-button
        >
      </div>
    </div>
    <!-- 设置 -->
    <setSendPage
      v-if="showSetSendPage"
      :visableIf.sync="showSetSendPage"
    ></setSendPage>
  </el-dialog>
</template>

<script>
import { listUser } from "@/api/system/user";

export default {
  name: "editSendSettings",
  components: {
    setSendPage: () => import("./setSendPage.vue"), //导出弹窗
  },
  data() {
    return {
      // 查询参数
      showSetSendPage: false,
      input3: null, //群查找
      radio: null, //
      groupList: [
        {
          value: "0",
          label: "志新",
        },
        {
          value: "1",
          label: "锐行",
        },
      ],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: "",
        group: null,
      },
      callList: [
        //称呼
        { id: 1, name: "有" },
        { id: 2, name: "无" },
      ],
      tableColumns: [
        {
          key: "name",
          label: `企微号`,
          visible: true,
          minWidth: 150,
          fixed: true,
        },
        {
          key: "name2",
          label: `消息发送间隔`,
          visible: true,
          minWidth: 150,
          fixed: true,
        },
        {
          key: "status",
          label: `休眠时段`,
          visible: true,
          minWidth: 150,
          fixed: true,
        },
      ],
      tableDataList: [],
      total: 8, // 表格的总条数
      multipleSelection: [], //表格多选
      tableHeight: 600,
      checked: false,
    };
  },
  created() {
    this.tableDataList = [];
    for (let i = 0; i < 10; i++) {
      let obj = {
        name: "小红",
        name2: "18207418337",
        status: "是",
      };
      this.tableDataList.push(obj);
    }
  },
  mounted() {},
  watch: {},
  methods: {
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listUser(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.userList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleSetting(row) {
      this.showSetSendPage = true;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.queryParams.deptId = undefined;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(val) {
      this.multipleSelection = [];
      if (val && val.length > 0) {
        val.forEach((item) => {
          this.multipleSelection.push(item.id);
        });
      }
    },
    handleSelectAll() {
      this.checked = true;
      this.$refs.multipleTable.toggleAllSelection();
    },

    handleSelectClear() {
      this.checked = false;
      this.$refs.multipleTable.clearSelection();
    },
    handleCloseDialog() {
      this.$emit("update:visableIf", false);
      this.$emit("handleQuery");
    },
  },
};
</script>

<style scoped lang="scss">
.number {
  position: absolute;
  left: 10px;
  top: 0px;
  font-size: 14px;
  span {
    color: rgba(0, 0, 0, 0.65);
    color: rgb(240, 139, 0);
  }
  .el-button {
    color: #3370ff;
    border: none;
  }
}
.footer-btn {
  position: relative;
}
.userInfo {
  border-radius: 4px;
  margin: 8px 0;
  cursor: pointer;
  position: relative;
  padding-left: 50px;
  font-size: 14px;
  list-style: none;
  text-align: left;
  display: flex;
  align-items: center;
  justify-items: center;

  img {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    left: 0px;
    top: 0px;
    position: absolute;
  }

  .label {
    margin-top: 2px;
    font-size: 12px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #f90;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .user-big {
    display: flex;
    flex-direction: column;
    line-height: 18px;
  }
}
.content-big {
  height: 100%;
  position: relative;
}
</style>
